package cn.ffcs.uec.salary.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.salary.dao.UecSalaryPlanDao;
import cn.ffcs.uec.salary.model.UecSalaryPlan;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecSalaryPlanDao")
@Transactional
public class UecSalaryPlanDaoImpl extends BaseDaoImpl implements UecSalaryPlanDao {

	@Override
	public PageInfo queryPageInfoByUecSalaryPlan(UecSalaryPlan uecSalaryPlan, int current,
			int pageSize) {
		if (null != uecSalaryPlan) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_SALARY_PLAN T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			
			// 薪资类别编码
			if (!StrUtil.isNullOrEmpty(uecSalaryPlan.getCode())) {
				sb.append(" AND T.CODE like ? ");
				params.add("%"+ uecSalaryPlan.getCode() + "%");
			}
			
			// 薪资类别名称
			if (!StrUtil.isNullOrEmpty(uecSalaryPlan.getName())) {
				sb.append(" AND T.NAME like ? ");
				params.add("%"+ uecSalaryPlan.getName() + "%");
			}
			
			// 起始期间
			if (!StrUtil.isNullOrEmpty(uecSalaryPlan.getStartperiod())) {
				sb.append(" AND T.STARTPERIOD = ? ");
				params.add(uecSalaryPlan.getStartperiod());
			}
			
			// 最新业务年度
			if (!StrUtil.isNullOrEmpty(uecSalaryPlan.getCyear())) {
				sb.append(" AND T.CYEAR = ? ");
				params.add(uecSalaryPlan.getCyear());
			}
			
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecSalaryPlan.class);
		} else {
			return null;
		}
	}
}
